package com.four.marketing.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.four.marketing.entity.Bargain;
import com.four.marketing.service.BargainService;
import com.four.marketing.vo.BargainVo;
import com.guli.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 侯新伟
 * @since 2021-12-14
 */
@RestController
@RequestMapping("mark/bargain")
public class BargainController {

    @Autowired
    private BargainService bargainService;

    /**
     * 砍价商品列表
     * @param page 当前页
     * @param pageSize 每页条数
     * @return 返回值
     */
    @PostMapping("/bargainList")
    public IPage<Bargain> bargainList(
            @RequestParam(value = "page",defaultValue = "1")Integer page,
            @RequestParam(value = "pageSize",defaultValue = "3")Integer pageSize,
            @RequestBody BargainVo vo
            ){


        return  bargainService.getList(page, pageSize,vo);
    }

    /**
     * 商品列表
     * @return 返回商品列表
     */
    @GetMapping("shopList")
    public R shopList() {

        return bargainService.shopList();
    }

    /**
     * 商品详情回显
     * @param manId
     * @return
     */
    @GetMapping("getShopById/{manId}")
    public R getShopById(@PathVariable("manId") Integer manId) {

        return bargainService.getShopById(manId);
    }


    /**
     * 添加
     */
    @PostMapping("saveBargain")
    public R saveBargain(@RequestBody Bargain bargain) {
        bargainService.saveBargain(bargain);
        return R.ok();
    }

    /**
     * 修改
     * @param bargain 需要修改的实体类
     * @return 返回值
     */
    @PostMapping("/updateBargain")
    public R updateBargain(@RequestBody Bargain bargain) {
        bargainService.updateBargain(bargain);
        return R.ok();
    }
}
